/**
 *@info 选择部门插件
 *@author: HJ
 *@date: 2012-05-24
 * */
if(typeof depchoice == "undefined"){
		if(typeof window.jQuery == "undefined"){
		
	   throw('由于没有加载jQuery库，所以本功能不能使用，请加载jQuery库，谢谢合作！');
	}
	function depchoice(_objs){
		
		var $sObj = this;
		
		var outStr = '';

		var posX;  
		
		var posY;  
		
		var popDiv;  
		
		var dragable;
		
		var _changeid_arr = [];
		
		var _changename_arr = [];
		
		var _changechkid_arr = [];
		
		$sObj.args = $.extend({
			wrap:window,/*绑定的位置*/
			treeid:'treeDemo',/*树绑定的位置*/
			topname:'',/*树的顶级名称*/
			left:'',/*组件左边位置*/
			top:'',/*组件顶部位置*/
			/*数据源（local为本地生成好的json串格式，ajax为需要动态加载数据的方式，需要配合url和ajaxdata使用,tree_JSON 构建树的内容,search_JSON构建搜索的内容，tree_JSON 和 search_JSON 只有在type为local时使用）*/
			datasource:{"type":"local","url":"","ajaxdata":"","tree_JSON":"","search_JSON":""},
			inputval:[],/*需要显示的数据(部门)，格式为json串*/
			inputempval:[],/*需要显示的数据(人员)，格式为json串*/
			sp:true,/*兼容老的方式返回值 true使用老的返回值方式,false使用新的返回值方式*/
			treeobj:'_tree',/*构建树的对象名称*/
			mode:'intricacy',/*有两种模式 简单(simple)和复杂(intricacy) 默认复杂模式(intricacy)*//*增加 select 为下拉样式*/
			rs:function(){},/*获得结果函数*/
			fun:function(){},/*外部函数*/
			location:'out',/*嵌入位置 外部out 内部in*/
			chkboxType:['ps','ps'],/*父子关联关系 p 父 s子*/
			selhalf:false,/*是否把半选也包含*/
			checked:false,/*是否显示复选框*/
			ver:'ver 1.0.0.0',/*版本*/
			dropDown:true /*改 随父级位置*/
		},_objs||{});
		
		/**
		 *@info 初始化设置
		 *@author: HJ
		 *@date: 2012-05-22
		 *@param null
		 *@return null
		 * */
		$sObj.creates = function(){
			/*构建html*/
			$sObj.createhtml();
			
			/*构建树*/
			$sObj.createtree($sObj.args.datasource.tree_JSON);
			
			if($sObj.args.mode != 'select'){
				/*层移动*/
				$sObj.divmove();
			}
			
			
			/*树搜索*/
			$sObj.search();
			
			/*绑定添加和删除按钮事件*/
			$sObj.optevent();
			
			/*搜索框事件*/
			$sObj.autocomplete();
			
			/*关闭、确定和取消按钮的单击事件*/
			$sObj.btnevent();
			/*如果不是简单模式才支持数据回显*/
			if ($sObj.args.mode != 'simple' || $sObj.args.checked == true){
				/*回显数据*/
				
				$sObj.reshowdata();
			}
		
		}
		
		/**
		 *@info 初始化数据源
		 *@author: HJ
		 *@date: 2012-05-24
		 *@param null
		 *@return null
		 * */
		$sObj.init = function(){
			$sObj.args.inputval = $sObj.inputval;
			$sObj.args.inputempval = $sObj.inputempval;

			if ($sObj.args.datasource.type == 'ajax'){
				
				/* 开始保存 */
				$.ajax({
					type:'post',
					url:$sObj.args.datasource.url,
					dataType:"json",
					cache:false,
					data:{
						type:'ajax',
						data:JSON.encode($sObj.args.datasource.ajaxdata),
                        user:JSON.encode($sObj.args.datasource._emp_show),
						counts:2
					},
					success:function(r){
						//alert(r.success);
						var ok = r;
						//alert(r);
						//console.log(ok.data)
						$sObj.args.datasource.tree_JSON = ok.data;
						
						$sObj.creates();
						
					}
				});
				
			}
			else
			{
				$sObj.creates();
			}
		}
		
		/**
		 *@info html建立
		 *@author: HJ
		 *@date: 2012-05-24
		 *@param null
		 *@return null
		 * */
		$sObj.createhtml = function(){
			if($('#dep-choice')){
				$('#dep-choice').remove()
			}
			var css1 = "css1";
			var css2 = "css2";
			var css7 = "css7";
			var css17 = "css17";
			var css22 = "css22";
			var css25 = "css25";
			var css30 = "css30";
			
			/*如果是简单模式*/
			if ($sObj.args.mode == 'simple' || $sObj.args.mode == 'select')
			{
				css1 = "css1_s";
				css2 = "css2_s";
				css7 = "css7_s";
				css17 = "css17_s";
				css22 = "css22_s";
				css25 = "css25_s";
				css30 = "css30_s";
			}
			if ($sObj.args.mode == 'select'){
				css1 = "css1_s2";
				css7 = "css7_s2";
				css11 ="css11_s2"
				css25 = "css25_s2";
			}
			$sObj.outStr =  '<div style="position: absolute;left:'+$sObj.args.left+'px;top:'+$sObj.args.top+'px;z-index:99999"  id="dep-choice" >';
			$sObj.outStr += '<div style="display:none">';
			$sObj.outStr += '<select size="6" id="select_group_left" class="select_c2"></select>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '<div class="'+css30+'" id="select_dep" >';
			$sObj.outStr += '<div class="color1">';
			//$sObj.outStr += '<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>';
			$sObj.outStr += '<div class="'+css1+'">';
			   //标题
				$sObj.outStr += '<div class="'+css2+'" id="titles">';
				$sObj.outStr += '<div class="css3"><font class="css4">&nbsp;请选择</font></div>';
				$sObj.outStr += '<div class="css5" ><font class="css6" id="btn_close_winodw">&nbsp;关闭</font></div>';
				$sObj.outStr += '</div>';
			$sObj.outStr += '<div class="'+css7+'" id="dep_edit">';
			$sObj.outStr += '<div class="css8">';
			$sObj.outStr += '<div class="css9">';
			$sObj.outStr += '<div class="css10">';
			$sObj.outStr += '<div class="searchs"><input id="input_search" type="text" class="ipt1"/><input id="btn_search" type="button" class="ipt2"/></div>';
			$sObj.outStr += '</div>';
				$sObj.outStr += '<div class="'+css11+'">';
				$sObj.outStr += '<div class="css12">';
				$sObj.outStr += '<div class="css13">组织架构</div>';
				$sObj.outStr += '</div>';
				$sObj.outStr += '</div>';
			$sObj.outStr += '<div class="css14">';
			$sObj.outStr += '<div id="treestyle" class="css15"></div>';
			//$sObj.outStr += '<div id="d_tree" class="css16"></div>';
			$sObj.outStr += '<div><ul id="'+$sObj.args.treeid+'" class="css16 ztree"></ul></div>';
			$sObj.outStr += '<div id="localsite">&nbsp;</div>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '<div class="'+css17+'">';
			$sObj.outStr += '<div class="css18">';
			$sObj.outStr += '<button id="btn_addgroup" class="add css19" style="display:none;"></button>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '<div class="css20" style="margin-left:60px;">';
			$sObj.outStr += '<button id="btn_delgroup" class="del css21" style="display:none;"></button>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '<div class="'+css22+'">';
			$sObj.outStr += '<div class="css23">';
			$sObj.outStr += '已选择';
			$sObj.outStr += '</div>';
			$sObj.outStr += '<div class="css24">';
			$sObj.outStr += '<div class="select_c1">';
			$sObj.outStr += '<select size="17"  id="select_group_right" multiple class="select_c2"></select>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '</div>';
				//按钮
				$sObj.outStr += '<div class="'+css25+'">';
				$sObj.outStr += '<div class="css26">';
				$sObj.outStr += '<button id="btn_s" style="display:none">上上</button><button id="btn_x" style="display:none">下下</button><button id="btn_confirm" class="save css27"></button>';
				$sObj.outStr += '&nbsp;';
				$sObj.outStr += '<button id="btn_cancel" class="qx css28"></button>';
				$sObj.outStr += '</div>';
				$sObj.outStr += '</div>';
			$sObj.outStr += '</div>';
			//$sObj.outStr += '<b class="b5"></b><b class="b6"></b><b class="b7"></b><b class="b8"></b> ';
			$sObj.outStr += '</div>';
			$sObj.outStr += '</div>';
			$sObj.outStr += '</div>';
			var _p = $sObj.args.wrap
			var panel = $($sObj.outStr).appendTo(document.body);
			if($sObj.args.mode == 'select'){
				panel.css({top:_p.offset().top,left:_p.offset().left})
			}else{
				panel.css({top: ($(window).height() - panel.height()) /2+$(document).scrollTop(), left: ($(window).width() - panel.width()) /2});
				$('#mask').height($(document).height());
			}
			$('#dep-choice').show();
		}
		
		/*初始化并显示*/
		$sObj.display = function(opt,func){
			
			if (opt == 'none'){
				$('#dep-choice').remove();
			}
			
			if (opt == 'show'){
				func();
			}
		}
		
		/*回显数据*/
		$sObj.reshowdata = function(){
			$sObj.args.inputval = eval($sObj.args.inputval);
			
			$sObj.args.inputempval = eval($sObj.args.inputempval);
			//console.log($sObj.args.inputval)	
			if (typeof $sObj.args.inputempval == 'undefined'){
				
				$sObj.args.inputempval = [];
				
			}
			if ($sObj.args.inputempval.length > 0)
			{

				var _option_emp = [];
				
				// for (var i = 0;i < $sObj.args.inputempval.length-1; i++)
				for (var i = 0;i < $sObj.args.inputempval.length; i++)//因为对字符串进行了处理后边没有,结尾了
				{	
					_option_emp[i] = "emp_"+$sObj.args.inputempval[i].id;
					
					/*搜索选中*/
					$sObj.searchsel(_option_emp[i],'id');
				}
				
			}
			/*如果为null返回*/
			if (isNull($sObj.args.inputval))
			{
				return false;
			}
			
			if ($sObj.args.inputval.length > 0)
			{
				var _option = [];
				
				for (var i = 0;i < $sObj.args.inputval.length; i++)
				{
					_option[i] = "dep_"+$sObj.args.inputval[i].id;

					/*搜索选中*/
					$sObj.searchsel(_option[i],'id');
				}
				
			}
			if($sObj.args.checked == true){
				/*获得所有选中的checkbox*/
				$sObj.chktrue();
			}
			
			 
			 
			$('#select_group_right').html($('#select_group_left').html());
		
		}
		
		
		/*清除缓存*/
		$sObj.clearval = function(){
			
			$('#dep-choice').remove();
			
			outStr = '';

			posX;  
			posY;  
			popDiv;  
			dragable;
			
			_changeid_arr = [];
			
			_changename_arr = [];
			
			_changechkid_arr = [];
			
		}
		
		$sObj.btnevent = function(){
			
			/*关闭窗体*/
			$('#btn_close_winodw,#btn_cancel').click(function(){
				
				$('#dep-choice').hide();
				$sObj.clearval();
				
				$sObj.args.fun();
				
			});
			
			if($sObj.args.mode == 'select'){
				$('#dep-choice').off('click').on('click',function(e){
					return false
				})
				$(document).off('click.dep-cho').on('click.dep-cho',function(){
					// alert(2)
					//$('#dep-choice').hide();
					$sObj.display('none')
					$sObj.clearval();
					
					$sObj.args.fun();
				})
			}
			/*开启窗体*/
			$('#opendiv').click(function(){
				
				$sObj.clearval();
				
				$('#dep-choice').show();
				
			});
			
			/*获得选中值*/
			$('#btn_confirm').click(function(){
				var returnVal = [];
				var _dep_arr = [];
				var _emp_arr = [];
				var _i = 0;
				var _ii = 0;

				
				/* 简单模式增加多选框显示  */
				var select_obj = $sObj.args.checked == true ? 'select_group_left' : 'select_group_right';

				$('#'+ select_obj +' option').each(function(e){

					/*部门值过滤*/
					var _dep_id_split_arr = $(this).val().split("dep_");

					/*人员值过滤*/
					var _emp_id_split_arr = $(this).val().split("emp_");

					/*如果是兼容模式就用老的方式进行返回值*/
					if ($sObj.args.sp){

						returnVal[e] = {"id":_dep_id_split_arr[1],"name":$(this).html()};

					}else{

						if (typeof _dep_id_split_arr[1] != 'undefined'){
							_dep_arr[_i] = {"id":_dep_id_split_arr[1],"name":$(this).html()};
							_i++;
						}

						if (typeof _emp_id_split_arr[1] != 'undefined'){
							_emp_arr[_ii] = {"id":_emp_id_split_arr[1],"name":$(this).html()};
							_ii++;
						}
					}

				});
				
				/*如果是兼容模式就用老的方式进行返回值*/
				if ( ! $sObj.args.sp){

					returnVal = [_dep_arr,_emp_arr];

				}

				$('#dep-choice').hide();
                //
                 $sObj.args.rs(JSON.encode(returnVal));//selecte重置
				//
				if($sObj.args.mode != 'select'){
					$('#mask').hide();
				}
				$sObj.clearval();
			});
			
		}
		/*改 当mode=select 时获得数据并返回数据给页面*/
		$sObj.getCheckDatas=function(data){
			var returnDatas=[]
			var _data= data,dep_arr=[],emp_arr=[]
			for(var i=0;i<_data.length;i++){
				/*部门值过滤*/
				var _dep_id_split_arr = _data[i]["id"].split("dep_");
				
				/*人员值过滤*/
				var _emp_id_split_arr = _data[i]["id"].split("emp_");
				if(typeof _dep_id_split_arr[1] != 'undefined'){
					dep_arr.push({"id":_dep_id_split_arr[1],"name":_data[i]["name"],da:_data[i]})
				}
				if (typeof _emp_id_split_arr[1] != 'undefined'){
					emp_arr.push({"id":_emp_id_split_arr[1],"name":_data[i]["name"],da:_data[i]})
				}
				returnDatas = [dep_arr,emp_arr]
			}
			$sObj.args.rs(JSON.encode(returnDatas));//
		}
		/*自动搜索*/
		$sObj.autocomplete = function(){
			
			$('#input_search').autocomplete($sObj.args.datasource.tree_JSON,{
                max: 12,					/*列表里的条目数*/
                minChars: 0,     			/*自动完成激活之前填入的最小字符*/
                scrollHeight: 300,   	/*提示的高度，溢出显示滚动条*/
                matchContains: true,    /*包含匹配，就是data参数里的数据，是否只要包含文本框里的数据就显示*/
                autoFill: false,    		/*自动填充*/
                formatItem: function(row, i, max){
                    return row.name;
                	},
                formatMatch: function(row, i, max){
                    return row.name;
                	},
                formatResult: function(row){
                		return row.name;
                	}
            }).result(function(event, row, formatted) {
            		
            });
		}
		
		/*添加或者删除选中的信息*/
		$sObj.optevent = function(){
			
				$('#btn_addgroup,#btn_delgroup').click(function(){
				
				switch ($(this).attr('id'))
				{
					case 'btn_addgroup':
						//if ($('#select_group_left').html() != '')
						//{
							$('#select_group_right').empty();
							
							$('#select_group_right').append($('#select_group_left').html());
						//}
						
						break;
						
					case 'btn_delgroup':
						
						var right_val = $('#select_group_right').val();
						
						var right_html = $('#select_group_right option[value='+right_val+']').html();
						
						var rigth_title = $('#select_group_right option[value='+right_val+']').attr('value');
						
						if ( right_val == null)
						{
							//alert("请选择需要删除项后进行操作！");
							return false;
						}
						
						var right_label = $('#select_group_right option[value='+right_val+']').parent().attr('label');
						
						var _pid = $('#select_group_right option[value='+right_val+']').attr('pid');
						
						$('#select_group_left option[value='+right_val+']').remove();
						
						$('#select_group_right option[value='+right_val+']').remove();
						
						var label_html = $('#select_group_right optgroup[label='+right_label+']').html();
						
						if (label_html == '')
						{
							
							$('#select_group_right optgroup[label='+right_label+']').remove();
						}
			
						$sObj.delarr(right_val,right_html);
						
						/*checkbox 状态改变*/
						$sObj.chkchange(rigth_title,false,'id');
						
						/*checkbox 单击事件*/
						$sObj.onCheck();

						$('#btn_addgroup').trigger('click');
						
						break;
					default:
						break;
				}
			});
		}

		
		/*层移动事件*/
		$sObj.divmove = function(){
			
			$('#dep-choice').mousedown(function(e){
				
				$sObj.down(e);
				
			}).mouseup(function(){
				
				$sObj.up();
				
			});
			
			$('#dep_edit').mouseover(function(){
				
				$('#dep-choice').unbind('mousedown');
				$('#dep-choice').unbind('mouseup');
				
			}).mouseout(function(){
				$('#dep-choice').mousedown(function(e){
					
					$sObj.down(e);
					
				}).mouseup(function(){
					
					$sObj.up();
					
				});
				
			});
		}
		
		
		
		/**
		 *@info 构建树 
		 *@author: HJ
		 *@date: 2012-03-15
		 @param string str_JSON 生成树的内容
		 *@return null
		 * */
		$sObj.createtree = function(str_JSON){
			
			
			var _check_enable = false;
			
			/*如果是简单模式*/
			// if ($sObj.args.checked == true || $sObj.args.mode != 'simple')
			if ($sObj.args.checked == true)
			{
				_check_enable = true;
			}
			
			var setting = {
					view: {
						selectedMulti: true
					},
					check: {
						enable: _check_enable,
						chkboxType:{"Y":$sObj.args.chkboxType[0],"N":$sObj.args.chkboxType[1]}
					},
					data: {
						simpleData: {
							enable: true,
							idKey: "id",
							pIdKey: "p_id",
							rootPId:999999
						}
					},
					callback: {
						onClick:$sObj.onClick,
						onCheck:$sObj.onCheck
					}
				};
				
				var zNodes = str_JSON;
				
				var code, log, className = "dark";
				
			
				$.fn.zTree.init($("#"+$sObj.args.treeid), setting, zNodes);

				
		}
		
		/*单击节点获取选中值*/
		$sObj.onClickVal = function() {
			
			$('#select_group_left').empty();
			
			_changeid_arr = [];
			_changename_arr = [];
			
			_changechkid_arr = [];
			
			var _select_obj = $sObj.selecttrue()[0];
			
			/* 增加选中事件  */
			$('#'+_select_obj.tId+'_check').trigger('click');

			if (typeof _select_obj != 'undefined'){
				
				$sObj.showdatas(_select_obj.id,_select_obj.name,true,_select_obj.tId);
				/*调用增加按钮*/
				$('#btn_addgroup').trigger('click');
			}
			
		}
		
		/*节点单击事件*/
		$sObj.onClick = function(e, treeId, treeNode) {
			
			/*如果是简单模式*/
			if ($sObj.args.mode == 'simple')
			{
				$sObj.onClickVal();
			}

			if($sObj.args.checked == false && $sObj.args.mode == 'select'){
				$sObj.getCheckDatas([treeNode])
			}

		}
		
		/*checkbox 单击事件*/
		$sObj.onCheck = function(e, treeId, treeNode) {

			$('#select_group_left').empty();
			
			_changeid_arr = [];
			
			_changename_arr = [];
			
			_changechkid_arr = [];
			
			/*获得所有选中的checkbox*/
			$sObj.chktrue();
			if($sObj.mode != 'select'){
				/*点击复选框自动添加选中*/
				$('#btn_addgroup').trigger('click');
			}
			
		}		
		
		/*获得选中的节点*/
		$sObj.selecttrue = function(){

			var treeObj=$.fn.zTree.getZTreeObj($sObj.args.treeid);
		    
			var nodes_true = treeObj.getSelectedNodes();

			return nodes_true;
			
		}
		
		/*获得所有选中的checkbox*/
		$sObj.chktrue = function(){

			var treeObj=$.fn.zTree.getZTreeObj($sObj.args.treeid);
			$('#select_group_left').html('');
			var _selectd = []
			var nodes_true = treeObj.getCheckedNodes(true);
			for(var i=0;i<nodes_true.length;i++){
				
				var _chk_status = nodes_true[i].getCheckStatus();
				
				if ($sObj.args.selhalf)
				{	
					if (_chk_status.checked == true || _chk_status.half == true){
						if($sObj.args.mode == 'select'){
							_selectd.push(nodes_true[i])
						}else{
							$sObj.showdatas(nodes_true[i].id,nodes_true[i].name,true,i,nodes_true[i].p_id);
						}
						
					}
				}
				else
				{	
					if (_chk_status.checked == true && _chk_status.half == false){
						if($sObj.args.mode == 'select'){
							_selectd.push(nodes_true[i])
						}else{
							$sObj.showdatas(nodes_true[i].id,nodes_true[i].name,true,i,nodes_true[i].p_id);
						}
						
					}
				}
			}
			if($sObj.args.mode == 'select'){
				//console.log(_selectd)
				$sObj.getCheckDatas(_selectd)
			}
			
		}
		
		/*勾选节点checkbox*/
		$sObj.chkchange = function(_c_val,status,tag){
			
			try{
				
				 var treeObj = $.fn.zTree.getZTreeObj($sObj.args.treeid);
				   
				 var selectNode = treeObj.getNodeByParam(tag,_c_val,null);
				  
				 treeObj.checkNode(selectNode,status,true);
			 
			}catch(e){
				
				/*忽略异常*/
				
			}
			
		}
		
		/*搜索选中*/
		$sObj.searchsel = function(_s_val,tag){
			try{
				
				 var treeObj = $.fn.zTree.getZTreeObj($sObj.args.treeid);
				  
				 var selectNode = treeObj.getNodeByParam(tag,_s_val,null);
				 treeObj.selectNode(selectNode);
				
				 /*如果是简单模式*/
				if ($sObj.args.mode != 'simple' || $sObj.args.checked == true){
					/*勾选节点checkbox*/
					treeObj.checkNode(selectNode,true);
					if($sObj.args.mode != 'select'){
						$sObj.chktrue();
						$('#btn_addgroup').trigger('click');
					}
					
				}
				

				
			}catch(e){
				/*忽略异常*/
				
			}

		}
		
		/*搜索事件*/
		$sObj.search = function(){

			$('#btn_search').click(function(){
				
				$sObj._search();
				 
			});
			
			$('#input_search').keydown(function(e){
			
				if (e.which == 13){
					
					$sObj._search();
					
				}
				
			});
			
			
		}
		
		$sObj._search = function(){
		
			$('#select_group_left').empty();
			
			var _s_val = $('#input_search').val().trim();
			
			if (_s_val == ''){
				return false;
			}
			
			/*搜索选中*/
			$sObj.searchsel(_s_val,'name');
			/*如果是简单模式*/
			if ($sObj.args.mode == 'simple'){
				
				/*单击节点获取选中值*/
				$sObj.onClickVal();
				
			}else{
				/*获得所有选中的checkbox*/
				 $sObj.chktrue();
				
			}
			try{
				if($sObj.args.mode == 'select' && !$sObj.args.checked){
					var selectNodes = $sObj.selecttrue()
					if(selectNodes.length != 0){
						$sObj.getCheckDatas(selectNodes)
						$sObj.display('none')
					}
				
				}
			}catch(e){

			}
			
			
		}
		
		/**
		 *@info 选择组(多选)
		 *@author: HJ
		 *@date: 2012-03-30
		 *@param int id 文件夹ID
		 *@param string name 文件夹名称
		 *@param boolean $chk 返回checkbox是否选中
		 *@param int chockid 树节点id
		 *@return null
		 * */
		$sObj.showdatas = function(id,name,$chk,chockid,pId){
			
			var _opt_str = '';
			if ($chk == true)
			{
				_changeid_arr.push(id);
				_changename_arr.push(name);
				_changechkid_arr.push(chockid);
				
				_opt_str = '<option value='+id+' title='+chockid+' pid='+pId+'>'+name+'</option>';
				
				$('#select_group_left').append(_opt_str);
			}

		}

		
		/*删除选中的id和名称*/
		$sObj.delarr = function(_val,_name){
			
			for (var i in _changeid_arr)
			{
				if (_changeid_arr[i] == _val)
				{
					_changeid_arr.splice(i,1);
				}
			}
			
			for (var ii in _changename_arr)
			{
				if (_changename_arr[ii] == _name)
				{
					_changename_arr.splice(ii,1);
				}
			}
		}
		
		/*鼠标按下并让鼠标移动获得层移动事件*/
		$sObj.down = function(e){ 
			
		    //popDiv = document.getElementById("dep-choice");  

		    e = e || window.event; //如果是IE
		    
		    var _left  = $('#dep-choice').css('left');
		    var _top  = $('#dep-choice').css('top');
		    
		    //posX = e.clientX - parseInt(popDiv.style.left);     
		   //posY = e.clientY - parseInt(popDiv.style.top);  
		
		    posX = e.clientX - parseInt(_left);     
			posY = e.clientY - parseInt(_top);  
		    
		    dragable = true;  
		    document.onmousemove = $sObj.move;  
		}  
		
		/*层移动事件*/
		$sObj.move = function(ev){  
		    if(dragable == true){  
		        ev = ev || window.event;//如果是IE  
		        
		        $('#dep-choice').css('left',function(){
		        	
		        	return (ev.clientX - posX) + "px";
		         });
		        
		        $('#dep-choice').css('top',function(){
		        	
		        	return (ev.clientY - posY) + "px";
		        });
		        
		        //popDiv.style.left = (ev.clientX - posX) + "px";     
		       //popDiv.style.top = (ev.clientY - posY) + "px";     
		    }  
		}  
		 
		/*鼠标按下弹起后取消层的移动*/
		$sObj.up = function(){  
		    dragable = false;  
		} 

	}
}
